package com.jbp.service.impl;

import com.jbp.dao.GiftLotDao;
import com.jbp.model.Gift;
import com.jbp.model.GiftLot;
import com.jbp.model.PrizeDeploy;
import com.jbp.service.GiftLotService;
import com.jbp.service.GiftService;
import com.jbp.service.PrizeDeployService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;



@Service
public class GiftLotServiceImpl extends ServiceImpl<GiftLotDao, GiftLot> implements GiftLotService {
    @Autowired
    private GiftService giftService;
    @Autowired
    private PrizeDeployService prizeDeployService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GiftLot> page = this.page(
                new Query<GiftLot>().getPage(params),
                new QueryWrapper<GiftLot>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<GiftLot> listByPoolType(String poolType) {
        List<GiftLot> list = list(new QueryWrapper<GiftLot>()
                .eq("pool_type", poolType));

        for (GiftLot giftLot : list) {
            giftLot.setGift(giftService.getById(giftLot.getGiftId()));
        }

        return list;
    }

    /**奖池列表*/
    @Override
    public List<GiftLot> poolList(String poolType) {
        PrizeDeploy deploy = prizeDeployService.getByPoolType(poolType);
        List<GiftLot> list = list(new QueryWrapper<GiftLot>()
                .eq("pool_id", deploy.getId())
                .orderByDesc("sort")
        );
        list.forEach( li -> {
            Gift gift=giftService.getById(li.getGiftId());
            if (gift != null){
                li.setGift(gift);
            }
        });
        return list;
    }
}
